package com.zjj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjj.entity.Dish;
import com.zjj.entity.R;
import com.zjj.mapper.DishMapper;
import com.zjj.service.DishService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements DishService {

    @Autowired
    private DishMapper dishMapper;

    @Override
    public R selectPage(Integer page, Integer size, Integer categoryId, String name) {
        Page pages = new Page<>(page,size);
        QueryWrapper queryWrapper = new QueryWrapper();
        if(categoryId != null){
            queryWrapper.eq("category_id",categoryId);
        }
        if(name != null){
            queryWrapper.like("name",name);
        }
        return R.success(dishMapper.selectPage(pages,queryWrapper));
    }

    @Override
    public R insert(Dish dish) {
        return R.success(dishMapper.insert(dish));
    }

    @Override
    public R delete(Integer id) {
        QueryWrapper queryWrapper =  new QueryWrapper();
        queryWrapper.eq("id",id);
        return R.success(dishMapper.delete(queryWrapper));
    }
}
